home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include "sw.h"
- #include "ship_regular.h"
- #include "resources.h"
- #include <Inventor/nodes/SoSeparator.h>
- #include <Inventor/nodes/SoLightModel.h>
- #include <Inventor/nodes/SoMaterial.h>
- #include <Inventor/nodes/SoRotation.h>
- #include <Inventor/nodes/SoTranslation.h>
- #include <Inventor/nodes/SoComplexity.h>
- #include <Inventor/nodes/SoCoordinate3.h>
- #include <Inventor/nodes/SoCone.h>
- #include <Inventor/nodes/SoFaceSet.h>
- #include <Inventor/nodes/SoShapeHints.h>
-
- static float shipGeometry[][3] = {
- // right body front face
- { -5.0, -8.0, -5.0 },
- { -10.0, -8.0, -5.0 },
- { -15.0, -5.0, -5.0 },
- { -15.0, 5.0, -5.0 },
- { -10.0, 8.0, -5.0 },
- { -5.0, 8.0, -5.0 },
- // right body back face
- { -5.0, 8.0, 15.0 },
- { -10.0, 8.0, 15.0 },
- { -15.0, 5.0, 15.0 },
- { -15.0, -5.0, 15.0 },
- { -10.0, -8.0, 15.0 },
- { -5.0, -8.0, 15.0 },
- // right body outside face
- { -15.0, 5.0, -5.0 },
- { -15.0, -5.0, -5.0 },
- { -15.0, -5.0, 15.0 },
- { -15.0, 5.0, 15.0 },
- // right body outside top face
- { -10.0, 8.0, -5.0 },
- { -15.0, 5.0, -5.0 },
- { -15.0, 5.0, 15.0 },
- { -10.0, 8.0, 15.0 },
- // right body outside bottom face
- { -15.0, -5.0, -5.0 },
- { -10.0, -8.0, -5.0 },
- { -10.0, -8.0, 15.0 },
- { -15.0, -5.0, 15.0 },
- // right body inside face
- { -5.0, 8.0, -5.0 },
- { -5.0, 8.0, 15.0 },
- { -5.0, -8.0, 15.0 },
- { -5.0, -8.0, -5.0 },
- // right body top face
- { -5.0, 8.0, 15.0 },
- { -5.0, 8.0, -5.0 },
- { -10.0, 8.0, -5.0 },
- { -10.0, 8.0, 15.0 },
- // right body bottom face
- { -5.0, -8.0, -5.0 },
- { -5.0, -8.0, 15.0 },
- { -10.0, -8.0, 15.0 },
- { -10.0, -8.0, -5.0 },
-
- // left body front face
- { 5.0, 8.0, -5.0 },
- { 10.0, 8.0, -5.0 },
- { 15.0, 5.0, -5.0 },
- { 15.0, -5.0, -5.0 },
- { 10.0, -8.0, -5.0 },
- { 5.0, -8.0, -5.0 },
- // left body back face
- { 5.0, -8.0, 15.0 },
- { 10.0, -8.0, 15.0 },
- { 15.0, -5.0, 15.0 },
- { 15.0, 5.0, 15.0 },
- { 10.0, 8.0, 15.0 },
- { 5.0, 8.0, 15.0 },
- // left body outside face
- { 15.0, -5.0, -5.0 },
- { 15.0, 5.0, -5.0 },
- { 15.0, 5.0, 15.0 },
- { 15.0, -5.0, 15.0 },
- // left body outside top face
- { 15.0, 5.0, -5.0 },
- { 10.0, 8.0, -5.0 },
- { 10.0, 8.0, 15.0 },
- { 15.0, 5.0, 15.0 },
- // left body outside bottom face
- { 10.0, -8.0, -5.0 },
- { 15.0, -5.0, -5.0 },
- { 15.0, -5.0, 15.0 },
- { 10.0, -8.0, 15.0 },
- // left body inside face
- { 5.0, -8.0, -5.0 },
- { 5.0, -8.0, 15.0 },
- { 5.0, 8.0, 15.0 },
- { 5.0, 8.0, -5.0 },
- // left body top face
- { 5.0, 8.0, -5.0 },
- { 5.0, 8.0, 15.0 },
- { 10.0, 8.0, 15.0 },
- { 10.0, 8.0, -5.0 },
- // left body bottom face
- { 5.0, -8.0, 15.0 },
- { 5.0, -8.0, -5.0 },
- { 10.0, -8.0, -5.0 },
- { 10.0, -8.0, 15.0 },
-
- // core top
- { 5.0, 2.0, 5.0 },
- { 5.0, 2.0, -10.0 },
- { -5.0, 2.0, -10.0 },
- { -5.0, 2.0, 5.0 },
- // core rear
- { 5.0, 2.0, 5.0 },
- { -5.0, 2.0, 5.0 },
- { -5.0, -2.0, 5.0 },
- { 5.0, -2.0, 5.0 },
- // core bottom
- { -5.0, -2.0, 5.0 },
- { -5.0, -2.0, -10.0 },
- { 5.0, -2.0, -10.0 },
- { 5.0, -2.0, 5.0 },
- // core right side
- { -5.0, 2.0, 5.0 },
- { -5.0, 2.0, -10.0 },
- { -5.0, -2.0, -10.0 },
- { -5.0, -2.0, 5.0 },
- // core left side
- { 5.0, 2.0, 5.0 },
- { 5.0, -2.0, 5.0 },
- { 5.0, -2.0, -10.0 },
- { 5.0, 2.0, -10.0 },
-
- // nose top
- { 5.0, 2.0, -10.0 },
- { 0.0, -2.0, -20.0 },
- { -5.0, 2.0, -10.0 },
- // nose bottom
- { 5.0, -2.0, -10.0 },
- { -5.0, -2.0, -10.0 },
- { 0.0, -2.0, -20.0 },
- // nose right side
- { -5.0, 2.0, -10.0 },
- { 0.0, -2.0, -20.0 },
- { -5.0, -2.0, -10.0 },
- // nose left side
- { 5.0, 2.0, -10.0 },
- { 5.0, -2.0, -10.0 },
- { 0.0, -2.0, -20.0 } };
- #define NUMCOORDS (sizeof(shipGeometry) / sizeof(float))
- static long shipGeometryEdges[] =
- { 6, 6, 4, 4, 4, 4, 4, 4, // right body
- 6, 6, 4, 4, 4, 4, 4, 4, // left body
- 4, 4, 4, 4, 4, // core
- 3, 3, 3, 3 }; // nose
- #define NUMEDGES (sizeof(shipGeometryEdges) / sizeof(long))
-
- RegularShip::RegularShip(NetId id, Team t, const char* n) : ShipObject(id, t, n)
- {
- SoSeparator* shipSep = new SoSeparator;
-
- SoMaterial* shipMat = new SoMaterial;
- shipSep->addChild(shipMat);
- shipMat->ambientColor.setValue(teamColor(t, 0.3));
- shipMat->diffuseColor.setValue(teamColor(t, 1.0));
- shipMat->specularColor.setValue(1.0, 1.0, 1.0);
- shipMat->shininess = 0.4;
-
- SoShapeHints* shipHints = new SoShapeHints;
- shipSep->addChild(shipHints);
- shipHints->hints = SoShapeHints::SOLID | SoShapeHints::ORDERED |
- SoShapeHints::CONVEX;
- shipHints->creaseAngle = 0.0;
-
- SoCoordinate3* shipCoord = new SoCoordinate3;
- shipSep->addChild(shipCoord);
- shipCoord->point.setValues(0, NUMCOORDS, shipGeometry);
-
- SoFaceSet* shipGeom = new SoFaceSet;
- shipSep->addChild(shipGeom);
- shipGeom->startIndex = 0;
- shipGeom->numVertices.setValues(0, NUMEDGES, shipGeometryEdges);
-
- SoMaterial* engineMat = new SoMaterial;
- shipSep->addChild(engineMat);
- engineMat->ambientColor.setValue(0.1, 0.1, 0.1);
- engineMat->diffuseColor.setValue(0.25, 0.25, 0.25);
-
- SoTranslation* enginePos1 = new SoTranslation;
- shipSep->addChild(enginePos1);
- enginePos1->translation.setValue(-9.0, 0.0, 14.0);
-
- SoRotation* engineRotate = new SoRotation;
- shipSep->addChild(engineRotate);
- engineRotate->rotation.setValue(SbRotation(SbVec3f(0.0, 1.0, 0.0),
- SbVec3f(0.0, 0.0, -1.0)));
-
- SoCone* engine = new SoCone;
- shipSep->addChild(engine);
- engine->parts = SoCone::SIDES;
- engine->height = 4.0;
- engine->bottomRadius = 6.0;
-
- SoTranslation* enginePos2 = new SoTranslation;
- shipSep->addChild(enginePos2);
- enginePos2->translation.setValue(18.0, 0.0, 0.0);
-
- engine = new SoCone;
- shipSep->addChild(engine);
- engine->parts = SoCone::SIDES;
- engine->height = 4.0;
- engine->bottomRadius = 6.0;
-
-
- SoSeparator* shipChangeSep = new SoSeparator;
- engineMat = new SoMaterial;
- shipChangeSep->addChild(engineMat);
- engineMat->ambientColor.setValue(0.0, 0.0, 0.0);
- engineMat->diffuseColor.setValue(0.0, 0.0, 0.0);
- engineMat->specularColor.setValue(0.0, 0.0, 0.0);
- engineMat->emissiveColor.setValue(0.0, 1.0, 1.0);
- engineMat->shininess = 0.0;
- engineMat->transparency = 0.5;
- enginePos1 = new SoTranslation;
- shipChangeSep->addChild(enginePos1);
- enginePos1->translation.setValue(-9, 0.0, 15.0);
- shipChangeSep->addChild(engineRotate);
-
- rightEngine = new SoCone;
- shipChangeSep->addChild(rightEngine);
- rightEngine->parts = SoCone::SIDES;
- rightEngine->height = 2.0;
- rightEngine->bottomRadius = 3.0;
-
- shipChangeSep->addChild(enginePos2);
-
- leftEngine = new SoCone;
- shipChangeSep->addChild(leftEngine);
- leftEngine->parts = SoCone::SIDES;
- leftEngine->height = 2.0;
- leftEngine->bottomRadius = 3.0;
-
- init(shipSep, shipChangeSep, SbVec3f(0.0, -5.5, -19.0),
- SbVec3f(0.0, 10.0 + 1.75 * FLAGSIZE, 10.0),
- SbVec3f(0.0, 0.0, -15.0));
- }
-
- RegularShip::~RegularShip()
- {
- }
-
- ShipClass RegularShip::shipClass() const
- {
- return ShipClassRegular;
- }
-
- float RegularShip::mass() const
- {
- return 50000.0; // kg
- }
-
- float RegularShip::angularAccel() const
- {
- return M_PI/3.0; // rad/s/s
- }
-
- float RegularShip::engineMaxForce() const
- {
- return 100.0 * 50000.0; // N
- }
-
- float RegularShip::engineResponse() const
- {
- return 0.6;
- }
-
- float RegularShip::fuelRate() const
- {
- return 0.01;
- }
-
- float RegularShip::shieldMaximum() const
- {
- return 100000.0; // J
- }
-
- float RegularShip::shieldRecovery() const
- {
- return 0.0; // J/s
- }
-
- int RegularShip::maxMissiles() const
- {
- return 20;
- }
-
- float RegularShip::missileEnergy() const
- {
- return 35000.0; // J
- }
-
- float RegularShip::laserPower() const
- {
- return 30000.0; // J/s
- }
-
- void RegularShip::newEngineOutput()
- {
- float e = 3.0 + 12.0 * engineOutput();
- if (e < 3.0) e = 1.0;
- rightEngine->height = 0.67 * e;
- rightEngine->bottomRadius = e;
- leftEngine->height = 0.67 * e;
- leftEngine->bottomRadius = e;
- }
-
- SbVec3f RegularShip::missileSource(int s) const
- {
- switch (s) {
- case 0: return SbVec3f(-8.0, -5.0, -5.0);
- case 1: return SbVec3f(-8.0, 5.0, -5.0);
- case 2: return SbVec3f(8.0, 5.0, -5.0);
- case 3: return SbVec3f(8.0, -5.0, -5.0);
- }
- return SbVec3f(0.0, 0.0, 0.0);
- }
-
- int RegularShip::missileSilos() const
- {
- return 4;
- }
-